package com.masterclient.app.modules.order;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;

import com.masterclient.app.R;
import com.eoner.baselibrary.utils.ScreenUtils;

/**
 * 作者：sean
 * 创建时间：2017/9/11 10:19
 * 功能说明：
 */

public class RedPackIntroDialog extends Dialog{

    ImageView ivClose;
    WebView webView;
    String url;
    public RedPackIntroDialog(@NonNull Context context,String url) {
        super(context, R.style.MyDialog);
        this.url = url;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_red_intro);
        setCanceledOnTouchOutside(true);
        ivClose = (ImageView) findViewById(R.id.iv_close);
        webView = (WebView) findViewById(R.id.webView);

        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);

        webView.setWebViewClient(new WebViewClient());

        webView.loadUrl(url);
        ivClose.setOnClickListener(v->{
            dismiss();
        });
    }


    @Override
    protected void onStart() {
        super.onStart();
        Window window = getWindow();
        WindowManager.LayoutParams windowparams = window.getAttributes();
        windowparams.width = ScreenUtils.getScreenWidth();
        window.setGravity(Gravity.CENTER);
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setAttributes(windowparams);
    }
}
